<?php
/**
* @package Joostina
* @copyright Авторские права (C) 2008-2009 Joostina team. Все права защищены.
* @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
* Joostina! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
* Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл help/copyright.php.
*/

// запрет прямого доступа
defined('_VALID_MOS') or die();

$_MAMBOTS->registerFunction( 'onPrepareContent', 'tjContent' );

function tjContent( $published, &$row, &$params, $page=0 ){
	global $Itemid, $_MAMBOTS,$task;

	$database = &database::getInstance();
	$mainframe = &mosMainFrame::getInstance();

	$root = $mainframe->getCfg('absolute_path');
	$lang = $mainframe->getCfg('lang');

	if ( file_exists( $root .DS.'mambots'.DS.'content'.DS.'tagj'.DS.'language'.DS.$lang.'.php' ) ) {
		include_once($root.DS.'mambots'.DS.'content'.DS.'tagj'.DS.'language'.DS.$lang.'.php');
	} else {
		include_once($root.DS.'mambots'.DS.'content'.DS.'tagj'.DS.'language'.DS.'russian.php');
	}

	// Hide adding tags on Modules - tags on modules is not supported 
	if (isset($row->content) or $task!='view' ){
		return true;
	}

	// check whether plugin has been unpublished
	if ( !$published ) {
		return true;
	}

	if ( !isset($_MAMBOTS->_content_mambot_params['tagJ']) ) {
		// load J!Tags info
		$query = "SELECT params"
		. "\n FROM #__mambots"
		. "\n WHERE element = 'tagJ'"
		. "\n AND folder = 'content'";
		$database->setQuery( $query );
		$database->loadObject($mambot);

		// save query to class variable
		$_MAMBOTS->_content_mambot_params['tagJ'] = $mambot;
	}
	
	$mambot = $_MAMBOTS->_content_mambot_params['tagJ'];
	$jparams = new mosParameters( $mambot->params );
	$tj		= $jparams->get( 'type_search');

	$show_link		= $jparams->get( 'show_link',1);
	$show_bookmark	= $jparams->get( 'show_bookmark',1);
	
	$text='';

	
	if($show_link || $show_bookmark) {
		// Create a proper link for this content item.
		$link = sefRelToAbs( "index.php?option=com_content&task=view&id=" . $row->id . "&Itemid=$Itemid" );
		// Create the html for the URL.
		$text .= '<div class="tagj">';
			if($show_link) {
				$text .= '<strong>'._TJ_LINK_FRIEND.'</strong>
							<div>'._TJ_LINK.':&nbsp;<input value="'.$link.'" onclick="this.focus();this.select();" type="text" style="width:99%"></div>
							<div>'._TJ_BB_CODE.':&nbsp;<input value="[url]'.$link.'[url]" onclick="this.focus();this.select();" type="text" style="width:99%"></div>
						</div>';
			}
			if($show_bookmark) {
				$text .= '<div class="tagj_bookmarks"><script language="javascript" type="text/javascript" src="'.$mainframe->getCfg('live_site').'/mambots/content/tagj/js/bookmarks.js"></script></div>';
			}
		$text .= '</div>';
	}
	
	$row->text .=$text;
	return true;
}